package com.qfedu.edu.manager;

import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.io.UnsupportedEncodingException;

/**
 * @author xiaobobo
 * @title: RabbitMQManager
 * @projectName cd-fy-2401-third-project-parent
 * @description: 这个就是向MQ中发送消息的地方
 * @date 2024/10/9  16:52
 */
@Component
public class RabbitMQManager {

    @Autowired
    private RabbitTemplate rabbitTemplate;


    /**
     * 向工作模型中发送数据
     *
     * @param queueName
     * @param msg
     */
    public void sendToWork(String queueName, String msg) throws UnsupportedEncodingException {
        Message message = new Message(msg.getBytes("UTF-8"));
        rabbitTemplate.send(queueName, message);
    }

    /**
     * 发送消息到交换机
     * @param exchangeName
     * @param routingKey
     * @param msg
     */
    public void sendToExchange(String exchangeName, String routingKey, String msg) throws UnsupportedEncodingException {
        Message message = new Message(msg.getBytes("UTF-8"));
        rabbitTemplate.send(exchangeName,routingKey,message);
    }
}
